package com.smalljj.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.apache.commons.codec.binary.Base64; 

public class SmalljjUtil {

	/**
	 * 获取当前时间，返回整型
	 * 
	 * @param strformat
	 * @return int
	 * 
	 */
	public static int getCurrentFormat(String strformat) {
		Calendar now = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat(strformat);
		String sr = formatter.format(now.getTime());
		return Integer.valueOf(sr).intValue();
	}
	
	/**
	 * 得到当前时间getCurrentFormatStr
	 * 
	 * @param strformat
	 * @return String
	 * 
	 */
	public static String getCurrentFormatStr(String strformat) {
		Calendar now = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat(strformat);
		String sr = formatter.format(now.getTime());
		return sr;
	}

	
	//android编码请看http://hi.baidu.com/xxfaxy/item/4c44f6fd4539dd5cc8f33705
	/**
	 * base64编码
	 * @param origin
	 * @return
	 */
    public static String encodeBase64(String origin) {
        if (origin == null) {
            return "";
        }
        return new String(Base64.encodeBase64(origin.getBytes()));
    }
    
	/**
	 * base64解码
	 * @param dest
	 * @return
	 */
    public static String decodeBase64(String dest) {
        if (dest == null) {
            return "";
        }
        return new String(Base64.decodeBase64(dest.getBytes()));
    }
    
    public static void main(String[] args) {
		System.out.println(encodeBase64("afds"));
	}  
}
